/**
 * 权限声明：
 */
package com.handy.webwork.action;

import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 基于IAction接口的抽象类，定义了一些用于返回值的常量，建议用户的控制器继承该类。
 * 
 * @author rocken.zeng@gmail.com
 * 
 */
public abstract class AbstractAction {

	public AbstractAction() {
	}

	/**
	 * 控制器的执行主体，必须实现。
	 */
	public abstract String execute();

	/**
	 * 处理页面传递过来的参数。
	 * @param form
	 */
	public abstract void getForm(ActionForm form);
	
	/**
	 * 将数据传递给视图。
	 */
	@SuppressWarnings("unchecked")
	public HashMap sendData(){
		HashMap root = new HashMap();
		root.put("authority", getAuthority());
		return root;
	}

	public abstract ActionMessage validate(ActionMessage actionMessage);

	private HttpSession session;
	private HttpServletRequest request;
	private HttpServletResponse response;
	private ServletContext context;
	private ActionMapping actionMapping;
	
	private Authority authority = new Authority();

	public Authority getAuthority() {
		return authority;
	}

	public void setAuthority(Authority authority) {
		this.authority = authority;
	}
	
	public ServletContext getContext() {
		return context;
	}

	public void setContext(ServletContext context) {
		this.context = context;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	

	public ActionMapping getActionMapping() {
		return actionMapping;
	}

	public void setActionMapping(ActionMapping actionMapping) {
		this.actionMapping = actionMapping;
	}
	
	/**
	 * 当execute()执行后返回该值时，系统拦截，取到sendData()中的handy_static_file键值
	 * 所指向的静态文件。
	 */
	public final static String HANDY_STATIC_FILE="handy_static_file";
	
	/**
	 * 当execute()执行后返回该值时，系统拦截，不处理视图的查找，由action自己处理response来返回。
	 */
	public final static String HANDY_ACTION_RESPONSE = "handy_action_response";
	
	/**
	 * Action指定ftl模板。当execute()执行后返回该值时，系统拦截，使用FreeMarker类处理,
	 * FreeMarker的模板取sendData()返回map中的handy_dyna_ftl键值所指向的文件。
	 */
	public final static String HANDY_DYNA_FTL = "handy_dyna_ftl";
	
	/**
	 * Action指定ftl输出模板时返回的contenttype
	 */
	public final static String HANDY_DYNA_FTL_CONTENT_TYPE = "handy_dyna_ftl_content_type";
	
	/**
	 * 执行成功
	 */
	public final static String SUCCESS="success";
	
	/**
	 * 执行失败
	 */
	public final static String FAILURE="failure";
		
	/**
	 * 浏览操作
	 */
	public final static String BROWSE="browse";
	
	/**
	 * 输入操作
	 */
	public final static String INPUT="input";
	
	/**
	 * 添加操作
	 */
	public final static String INSERT="insert";
	
	/**
	 * 添加前的操作
	 */
	public final static String BEFORE_INSERT="beforeInsert";
	
	/**
	 * 修改操作
	 */
	public final static String UPDATE="update";
	
	/**
	 * 修改前的操作
	 */
	public final static String BEFORE_UPDATE="beforeUpdate";
	
	/**
	 * 删除操作
	 */
	public final static String DELETE="delete";
	
	/**
	 * 删除前的操作
	 */
	public final static String BEFORE_DELETE="beforeDelete";

}
